package com.bright.ghj.overt.repository.primary;

import com.bright.ghj.overt.pojo.po.primary.MainModal;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface MainModalRepository extends JpaRepository<MainModal, Integer>, JpaSpecificationExecutor<MainModal> {

    @Query("from MainModal where length(modalId)=4 and tableName is not null and defMonths is not null and modalId like :modalId% and isShow=true order by modalId ")
    List<MainModal> findMainModalStartsWithModalId(@Param("modalId") String modalId);

    /**
     * 根据表名获取mainModal对象
     * @param tableName 公开表名
     * @return
     */
    @Query("from MainModal where tableName=:tableName and isShow=true order by sortNo")
    List<MainModal> listMainModalByTableName(@Param("tableName") String tableName);

    /**
     * 获取子表的mainModal配置
     * @param modalId
     * @return
     */
    @Query("from MainModal where length(modalId)=6 and tableName is not null and modalId like :modalId% and isShow=true order by modalId ")
    List<MainModal> findSubModalStartsWithModalId(@Param("modalId") String modalId);

    /**
     * 根据samePageTab获取展示在同一页的 包含主表、子表在内的mainModal列表
     * @param samePageTab
     * @return
     */
    @Query("from MainModal where tableName is not null and samePageTab=:samePageTab and isShow=true order by modalId")
    List<MainModal> findMainModalsBySamePageTab(@Param("samePageTab") Integer samePageTab);

}